<?php
namespace app\mobile\controller;
use think\Db;
use think\Controller;
use think\Request;
use think\Cookie;
use think\Session;

class Personal extends Controller
{
    public function index()
    {
        ( empty(cookie::get('loginid')) && empty(session::get('user')) )? $uid = '' : (!empty(session::get('user'))? $uid = session::get('user.id') : $uid = cookie::get('loginid'));
    	  $data = Db::table('s75_user')->where('id',$uid)->find();
        $this->assign('data',$data);
        return $this->fetch('personal/index');
    }

    public function info($id)
    {
       $data = Db::table('s75_user')->where('id',$id)->find();
       $data['rtime'] = date('Y-m-d h:i:s',$data['rtime']);
       $this->assign('data',$data);
       return $this->fetch('personal/info');
    }

    public function collect($id)
    {
    	$data = Db::table('s75_user')->where('id',$id)->find();
        $this->assign('data',$data);
    	$list = Db::field('d.name,d.face,c.id,d.id as did')
                ->table(['s75_data'=>'d','s75_collect'=>'c'])
                ->where('d.id=c.cid')->where('c.uid='.$id)
                ->select();
        $this->assign('list',$list);
        return $this->fetch('personal/collect');
    }

    public function mybook($id)
    {
       $data = Db::table('s75_user')->where('id',$id)->find();
       $this->assign('data',$data);
       $list = Db::field('d.id as did,d.name,d.face,o.order_number,o.pay_money,o.status,otime')
                ->table(['s75_data'=>'d','s75_orders'=>'o'])
                ->where('d.id=o.cid')->where('o.status=1')->where('o.uid='.$id)
                ->select();
        $this->assign('list',$list);
        return $this->fetch('personal/mybook');
    }

    public function change($id)
    {
    	$data = Db::table('s75_user')->where('id',$id)->find();
        $this->assign('data',$data);
        return $this->fetch('personal/change');
    }

   
    public function buycar($id)
    { 
        $data = Db::table('s75_user')->where('id',$id)->find();
        $this->assign('data',$data);
        $list = Db::field('d.id as did,d.name,d.face,o.pay_money,d.author,o.id')
                ->table(['s75_data'=>'d','s75_orders'=>'o'])
                ->where('d.id=o.cid')->where('o.status=0')->where('o.uid='.$id)
                ->select();
        $this->assign('list',$list);
        
        return $this->fetch('personal/buycar');

    }

    public function pwd($id)
    {
      $data = Db::table('s75_user')->where('id',$id)->find();
      $this->assign('data',$data);
      return $this->fetch('personal/pwd');
    }

     public function logout()
    {
        Session::delete('mlogin');
        $this->redirect('mobile/index/index');

    }

    public function icon($id)
    {
      $data = Db::table('s75_user')->where('id',$id)->find();
      $this->assign('data',$data);
      return $this->fetch('personal/icon');
    }


}
